<?php
global $_GPC, $_W;

$GLOBALS['frames'] = $this->getMainMenu2();





//var_dump($info);die;

if(checksubmit('submit')){

    require_once("../addons/zh_tcwq/PHPExcel/PHPExcel/IOFactory.php");
    $file = $_FILES['file'];
    if ($file['error'] == 4) message('请选择上传excel文件','','error');
    $file_types = explode ( ".", $file['name'] );
    $excel_type = array('xls','csv','xlsx');
    if (!in_array(strtolower(end($file_types)),$excel_type)){
      message('不是Excel文件，请重新上传','','error');
    }
    $objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本，因为office版本可以向下兼容
    $objPHPExcel = $objReader->load($file['tmp_name'],$encode='utf-8');//$file 为解读的excel文件
    $sheet = $objPHPExcel->getSheet(0)->toArray();

    foreach ($sheet as $key => $value) {
        $data['uniacid'] = $_W['uniacid'];
        $data['cid'] = $_GPC['cid'];
        $data['city_id'] = $_COOKIE['account_id'];
        $data['code'] = $value[0];
        $data['addtime'] = date("Y-m-d H:i:s");
        
        $res=pdo_insert('zhtc_video_card_data',$data);

    }
 

if($res){
     message('添加成功！', $this->createWebUrl('carddata',array('cid'=> $_GPC['cid'],'state'=>0)), 'success');
}else{
     message('添加失败！','','error');
}
   
}
include $this->template('web/addcarddata');